< previous page page_449 next page >

Page 449
The next method you need to create is the Item() method. This method needs to accept a variant argument because you can pass either a numeric value or a string value to the Item() method of the Collection class:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Function Item(vntValue As Variant) As Employee
   Dim oEmp As Employee

   On Error Resume Next

   Set oEmp = mcolEmps.Item(vntValue)
   If oEmp Is Nothing Then
      Set Item = Nothing
   Else
      Set Item = oEmp
   End If
End Function
This method is very simple to write. First, lets set an error trap to ignore any errors that may occur when you attempt to access the Item method. This way, you can just check the Employee object after the Item method executes to see whether you have anything in the Employee object. If its Nothing, you know that you didnt find the object. Otherwise, a valid Employee object is returned from this Item method.
You also need a Count property in your Employees class. This property just needs to return the Count property in the private collection in your Employees class:
9f31265bb40b592b1929e18a47ab28e5.gif
Property Get Count() As Integer
   Count = mcolEmps.Count
End Property
The last method you need to implement is the Remove() method. This method also needs to accept a variant argument because either an index number or a Key string can be passed to the Remove method of the Collection class:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Sub Remove(ByVal vntValue As Variant)
   mcolEmps.Remove vntValue
End Sub

 
< previous page page_449 next page >

If you like this book, buy it!